package project.newCode.scenegraph;

import java.util.ArrayList;

import project.hulpPakket.Matrix4f;
import project.hulpPakket.Point3f;
import project.hulpPakket.Scene;
import project.hulpPakket.Vector3f;
import project.newCode.Ray;
import project.newCode.surfaces.Hittable;
import project.newCode.surfaces.Surface;

public class SceneTraverserPreprocessor extends SceneTraverser {

	private ArrayList<Hittable> contents;
	public SceneTraverserPreprocessor(Scene s) {
		super(s);
		contents = new ArrayList<Hittable>();
	}
	
	public ArrayList<Hittable> getContents() {
		CompositeTransform c = scene.getRoot();
		c.enter(this);
		return contents;
	}

	
	@Override
	public void visitEntry(LeafShape leafShape) {
		Surface s = scene.getSurface(leafShape.getGeometry());
		s.setMaterial(scene.getMaterial(leafShape.getMaterial()));
		Matrix4f m = getRightProduct();
		Matrix4f minverse = getLeftProduct();
		ArrayList<Surface> temp = s.getSurfaceList();
		for(Surface surface : temp) {
			contents.add(surface.Transform(m, minverse));
		}

	}

}
